package thinkinginjava.container;

import java.util.HashMap;
import java.util.Map;

public class MapDemos {
	public static void main(String[] args) {
		performanceOfCapacity();
	}
	
	public static void performanceOfCapacity() {
		final CopyHashMap<Integer, Integer> map = new CopyHashMap<Integer, Integer>(16);
		map.put(null, null);
		map.put(null, 1);
		System.out.println(map.get(null));
		for(int i = 0; i < 10000; i ++) {
			map.put(i, i);
		}
		printMapInfo(map);
		TimePerformance.getAvgNanoTime(new Performancable() {
			@Override
			public String getDescription() {
				return "Hash Map putting";
			}

			@Override
			public void run() {
				map.get(5000);
			}
		});
		
		final CopyHashMap<Integer, Integer> map1 = new CopyHashMap<Integer, Integer>(16, 0.1f);
		for(int i = 0; i < 10000; i ++) {
			map1.put(i, i);
		}
		printMapInfo(map1);
		TimePerformance.getAvgNanoTime(new Performancable() {
			@Override
			public String getDescription() {
				return "Hash Map putting with capacity";
			}

			@Override
			public void run() {
				map1.get(5000);
			}
		});
		
		final CopyHashMap<Integer, Integer> map2 = new CopyHashMap<Integer, Integer>(16, 1f);
		for(int i = 0; i < 10000; i ++) {
			map2.put(i, i);
		}
		printMapInfo(map2);
		TimePerformance.getAvgNanoTime(new Performancable() {
			@Override
			public String getDescription() {
				return "Hash Map putting with capacity & loadfactor";
			}

			@Override
			public void run() {
				map2.get(5000);
			}
		});
	}
	
	static void printMapInfo(CopyHashMap map) {
		System.out.println("Capacity: " + map.capacity() + " Resize Times: " + map.resizeTimes);
	}
}
